import { View } from '@tarojs/components';
import Title from '@/components/Title';
import { AtDivider } from 'taro-ui';
import EmptyContent from '@/components/EmptyContent';
import Taro from '@tarojs/taro';
import GoodsItem from '../GoodsItem/index';
import './index.scss';

interface ListItem {
  id: number | string;
  imageUrl: string;
  name: string;
  price: number;
}
interface IProps {
  title: string;
  subTitle: string;
  list: ListItem[];
  type?: string;
}

/**
 * 产品列表
 */
export default function ({ title, subTitle, list = [], type }: IProps) {
  const onHandle = (goods: any) => {
    let _type: any = type;
    if (!type) {
      _type = goods.type === 0 ? 'product' : 'service';
    }
    Taro.navigateTo({
      url: `/pages/contrast/detail/index?goods_sn=${goods.goods_sn}&type=${_type}`,
    });
  };
  return (
    <View className="product-list-section">
      <Title title={title} subTitle={subTitle} />
      <View className="product-list">
        {list.map((item) => {
          return <GoodsItem key={item.id} goodsInfo={item} onHandle={() => onHandle(item)} />;
        })}
      </View>
      {
        list.length !== 0 && <AtDivider content="~没有更多了~" fontColor="#aaa" lineColor="transparent" />
      }
      {list.length === 0 && <EmptyContent offsetTop={50} title="暂无内容" />}
    </View>
  );
}
